home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Table / Sources / Commands.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  23.4 KB  |  749 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Commands.cpp
  4. //    Release Version:    $ ODF 3 $ 
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef COMMANDS_H
  11. #include "Commands.h"
  12. #endif
  13.  
  14. #ifndef FRAME_H
  15. #include "Frame.h"
  16. #endif
  17.  
  18. #ifndef PART_H
  19. #include "Part.h"
  20. #endif
  21.  
  22. #ifndef SELECTION_H
  23. #include "Selection.h"
  24. #endif
  25.  
  26. #ifndef PROXY_H
  27. #include "Proxy.h"
  28. #endif
  29.  
  30. #ifndef LINKING_H
  31. #include "Linking.h"
  32. #endif
  33.  
  34. #ifndef CONTENT_H
  35. #include "Content.h"
  36. #endif
  37.  
  38. // ----- Framework Includes -----
  39.  
  40. #ifndef FWPART_H
  41. #include "FWPart.h"
  42. #endif
  43.  
  44. #ifndef FWFRAME_H
  45. #include "FWFrame.h"
  46. #endif
  47.  
  48. #ifndef FWSELECT_H
  49. #include "FWSelect.h"
  50. #endif
  51.  
  52. #ifndef FWBARRAY_H
  53. #include "FWBArray.h"
  54. #endif
  55.  
  56. #ifndef FWFRMING_H
  57. #include "FWFrming.h"
  58. #endif
  59.  
  60. #ifndef FWLNKMGR_H
  61. #include "FWLnkMgr.h"
  62. #endif
  63.  
  64. #ifndef FWSESION_H
  65. #include "FWSesion.h"
  66. #endif
  67.  
  68. #ifndef FWINTER_H
  69. #include "FWInter.h"
  70. #endif
  71.  
  72. // ----- OpenDoc Includes -----
  73.  
  74. #ifndef SOM_Module_OpenDoc_Commands_defined
  75. #include <CmdDefs.xh>
  76. #endif
  77.  
  78. #ifndef SOM_ODDragAndDrop_xh
  79. #include <DragDrp.xh>
  80. #endif
  81.  
  82. //========================================================================================
  83. //    Runtime Info
  84. //========================================================================================
  85.  
  86. #ifdef FW_BUILD_MAC
  87. #pragma segment odfTable
  88. #endif
  89.  
  90. FW_DEFINE_AUTO(CCellDragCommand)
  91. FW_DEFINE_AUTO(CCellDropCommand)
  92. FW_DEFINE_AUTO(CTableEditCommand)
  93. FW_DEFINE_AUTO(CTableInsertCommand)
  94.  
  95. //========================================================================================
  96. //    class CCellDragCommand
  97. //========================================================================================
  98.  
  99. //----------------------------------------------------------------------------------------
  100. //    CCellDragCommand constructor
  101. //----------------------------------------------------------------------------------------
  102.  
  103. CCellDragCommand::CCellDragCommand(    Environment* ev,
  104.                                     CTablePartContent* tableContent,
  105.                                     FW_CFrame* frame,
  106.                                     CTableSelection* selection) : 
  107.     FW_CDragCommand(ev, frame, FW_kCanUndo),
  108.     fTableContent(tableContent),
  109.     fTableSelection(selection),
  110.     fSavedProxy(NULL)
  111. {
  112.     fDragCell = selection->GetSelectedCell();
  113.     FW_END_CONSTRUCTOR
  114. }
  115.  
  116. //----------------------------------------------------------------------------------------
  117. //    CCellDragCommand destructor
  118. //----------------------------------------------------------------------------------------
  119.  
  120. CCellDragCommand::~CCellDragCommand()
  121. {
  122.     FW_START_DESTRUCTOR
  123.     
  124.     if (fSavedProxy)
  125.         fSavedProxy->Release();
  126. }
  127.  
  128. //---------------------------------------------------------------------------------------
  129. //    CCellDragCommand::UndoIt
  130. //---------------------------------------------------------------------------------------
  131. void CCellDragCommand::UndoIt(Environment* ev)
  132. {
  133.     FW_ASSERT(fSavedProxy);
  134.  
  135.     // Restore saved proxy to the table
  136.     fSavedProxy->AttachEmbeddedFrames(ev);
  137.     fTableContent->AddProxy(fSavedProxy);
  138.     fTableSelection->SelectProxy(ev, fSavedProxy);
  139. }
  140.  
  141. //---------------------------------------------------------------------------------------
  142. //    CCellDragCommand::RedoIt
  143. //---------------------------------------------------------------------------------------
  144. void CCellDragCommand::RedoIt(Environment* ev)
  145. {
  146.     // Remove saved proxy, again
  147.     fTableSelection->SelectProxy(ev, fSavedProxy);
  148.     fTableSelection->ClearSelection(ev);
  149. }
  150.  
  151. //---------------------------------------------------------------------------------------
  152. //    CCellDragCommand::SaveUndoState
  153. //---------------------------------------------------------------------------------------
  154. void CCellDragCommand::SaveUndoState(Environment* ev)
  155. {
  156. FW_UNUSED(ev);
  157.     // Save the proxy for the part that was dragged
  158.     fSavedProxy = fTableContent->CellToProxy(fDragCell);
  159.     fSavedProxy->Acquire();
  160. }
  161.  
  162. //---------------------------------------------------------------------------------------
  163. //    CCellDragCommand::FreeUndoState
  164. //---------------------------------------------------------------------------------------
  165.  
  166.  
  167. //========================================================================================
  168. //    class CCellDropCommand
  169. //========================================================================================
  170.  
  171. //----------------------------------------------------------------------------------------
  172. //    CCellDropCommand constructor
  173. //----------------------------------------------------------------------------------------
  174.  
  175. CCellDropCommand::CCellDropCommand(    Environment* ev,
  176.                                     CTablePart* itsPart,
  177.                                     CTablePartContent* tableContent,
  178.                                     CTableFrame* frame,
  179.                                     ODDragItemIterator* dropInfo, 
  180.                                     ODFacet* odFacet,
  181.                                     const FW_CPoint& dropPoint,
  182.                                     const CCell& dropCell,
  183.                                     const CCell& draggedCell) : 
  184.     FW_CDropCommand(ev, frame, dropInfo, odFacet, dropPoint, FW_kCanUndo),
  185.     fTablePart(itsPart),
  186.     fTableContent(tableContent),
  187.     fTableFrame(frame),
  188.     fDropCell(dropCell),
  189.     fDraggedCell(draggedCell),
  190.     fSavedProxy(NULL),
  191.     fLinkCreated(false)
  192. {
  193.     // If this was a Cmd-drag, set the selection to the dropCell for DoDroppedPasteAs
  194.     ODDragAndDrop* drag = FW_CSession::GetDragAndDrop(ev);
  195.     unsigned long attributes = drag->GetDragAttributes(ev);
  196.     if (attributes & kODDropIsPasteAs)
  197.         fTableFrame->SelectCell(ev, fDropCell);
  198.  
  199.     FW_END_CONSTRUCTOR
  200. }
  201.  
  202. //----------------------------------------------------------------------------------------
  203. //    CCellDropCommand destructor
  204. //----------------------------------------------------------------------------------------
  205.  
  206. CCellDropCommand::~CCellDropCommand()
  207. {
  208.     FW_START_DESTRUCTOR
  209.     
  210.     if (fSavedProxy != NULL)
  211.         fSavedProxy->Release();
  212. }
  213.  
  214. //----------------------------------------------------------------------------------------
  215. // CCellDropCommand::DoDrop
  216. //----------------------------------------------------------------------------------------
  217.  
  218. FW_Boolean CCellDropCommand::DoDrop(Environment* ev, 
  219.                                     ODStorageUnit* dropSU, 
  220.                                     const FW_CPoint& mouseDownOffset,
  221.                                     const FW_CPoint& dropPoint,
  222.                                     FW_Boolean isDropMove,
  223.                                     short itemNumber)
  224. {
  225.     if (itemNumber > 1)        // can only drop one item in a cell
  226.         return false;
  227.  
  228.     fTableFrame->SelectCell(ev, fDropCell);
  229.     
  230.     return FW_CDropCommand::DoDrop(ev, dropSU, mouseDownOffset, dropPoint, isDropMove, itemNumber);
  231. }
  232.  
  233. //----------------------------------------------------------------------------------------
  234. // CCellDropCommand::DoDroppedInSameFrame
  235. //----------------------------------------------------------------------------------------
  236.  
  237. FW_Boolean CCellDropCommand::DoDroppedInSameFrame(Environment* ev, 
  238.                                                   ODStorageUnit* dropSU, 
  239.                                                   const FW_CPoint& mouseDownOffset, 
  240.                                                   const FW_CPoint& dropPoint)
  241. {
  242.     FW_UNUSED(dropSU);
  243.     FW_UNUSED(mouseDownOffset);
  244.     FW_UNUSED(dropPoint);
  245.     
  246.     FW_ASSERT(fDropCell != fDraggedCell);
  247.     
  248.     // Move the frame's cell
  249.     
  250.     CTableProxy* proxy = fTableContent->CellToProxy(fDraggedCell);
  251.     FW_ASSERT(proxy);
  252.  
  253.     fTableFrame->MoveProxy(ev, proxy, fDropCell);
  254.     fTablePart->ProxyMoved(ev, fDraggedCell, fDropCell);
  255.  
  256.     return TRUE;
  257. }
  258.  
  259. //---------------------------------------------------------------------------------------
  260. //    CCellDropCommand::DoDroppedPasteAs
  261. //---------------------------------------------------------------------------------------
  262. void CCellDropCommand::DoDroppedPasteAs(Environment* ev, 
  263.                                         const FW_CPoint& mouseDownOffset, 
  264.                                         const FW_CPoint& dropPoint)
  265. {
  266.     FW_UNUSED(mouseDownOffset);
  267.     FW_UNUSED(dropPoint);
  268.  
  269.     // Remember whether a link was created
  270.     fLinkCreated = (GetNewLink(ev) != NULL);
  271. }
  272.  
  273. //---------------------------------------------------------------------------------------
  274. //    CCellDropCommand::UndoIt
  275. //---------------------------------------------------------------------------------------
  276. void CCellDropCommand::UndoIt(Environment* ev)
  277. {
  278.     // Get a valid frame
  279.     CTableFrame* tableFrame = (CTableFrame*) GetFrame(ev);
  280.  
  281.     if (this->IsDragMoveInSameFrame(ev))    // simple move from one cell to another
  282.     {
  283.         // move the dropped part back to the cell it came from
  284.         tableFrame->MoveProxy(ev, fSavedProxy, fDraggedCell);
  285.         fTablePart->ProxyMoved(ev, fDropCell, fDraggedCell);
  286.     }
  287.     else    // part was dropped here from outside
  288.     {
  289.         if (fLinkCreated)            // a link was created
  290.         {
  291.             // with links, proxy did not exist yet when command was 'done', and may
  292.             // change between redoing and undoing. Get it from the cell now.
  293.             if (fSavedProxy)
  294.                 fSavedProxy->Release();
  295.                 
  296.             fSavedProxy = fTableContent->CellToProxy(fDropCell);
  297.             fSavedProxy->Acquire();
  298.         }
  299.         
  300.         // remove the dropped cell from the table
  301.         CTableSelection* selection = tableFrame->GetSelection(ev);
  302.         selection->SelectProxy(ev, fSavedProxy);
  303.         selection->ClearSelection(ev);
  304.     }
  305. }
  306.  
  307. //---------------------------------------------------------------------------------------
  308. //    CCellDropCommand::RedoIt
  309. //---------------------------------------------------------------------------------------
  310. void CCellDropCommand::RedoIt(Environment* ev)
  311. {
  312.     // Get a valid frame
  313.     CTableFrame* tableFrame = (CTableFrame*) GetFrame(ev);
  314.  
  315.     if (this->IsDragMoveInSameFrame(ev))    // simple move from one cell to another
  316.     {
  317.         // move the dropped part to the cell it was dropped in
  318.         tableFrame->MoveProxy(ev, fSavedProxy, fDropCell);
  319.         fTablePart->ProxyMoved(ev, fDraggedCell, fDropCell);
  320.     }
  321.     else    // part was dropped here from outside
  322.     {
  323.         // re-drop the cell
  324.         fSavedProxy->AttachEmbeddedFrames(ev);
  325.         fTableContent->AddProxy(fSavedProxy);
  326.         tableFrame->SelectCell(ev, fDropCell);
  327.         fTablePart->GetTableSelection(ev)->InvalidateSelection(ev);
  328.     }
  329. }
  330.  
  331. //---------------------------------------------------------------------------------------
  332. //    CCellDropCommand::SaveRedoState
  333. //---------------------------------------------------------------------------------------
  334. void CCellDropCommand::SaveRedoState(Environment* ev)
  335. {
  336. FW_UNUSED(ev);
  337.  
  338.     FW_ASSERT(fSavedProxy == NULL);
  339.  
  340.     if (!fLinkCreated)
  341.     {
  342.         // Save the proxy for the part that was just dropped
  343.         fSavedProxy = fTableContent->CellToProxy(fDropCell);
  344.         fSavedProxy->Acquire();
  345.     }
  346. }
  347.  
  348. //---------------------------------------------------------------------------------------
  349. //    CCellDropCommand::FreeRedoState
  350. //---------------------------------------------------------------------------------------
  351. void CCellDropCommand::FreeUndoState(Environment* ev)
  352. {
  353.     if (fSavedProxy)
  354.         fSavedProxy->CommitPasteDone(ev);
  355. }
  356.  
  357. //========================================================================================
  358. // CTableEditCommand class
  359. //========================================================================================
  360.  
  361. //---------------------------------------------------------------------------------------
  362. // CTableEditCommand constructor
  363. //---------------------------------------------------------------------------------------
  364. CTableEditCommand::CTableEditCommand(Environment* ev,
  365.                                      ODCommandID id,
  366.                                      CTablePart* itsPart, 
  367.                                      CTablePartContent* tableContent,
  368.                                      FW_CFrame* frame, 
  369.                                      CTableSelection* selection) :
  370.     FW_CClipboardCommand(ev, id, frame, FW_kCanUndo),
  371.     fTablePart(itsPart),
  372.     fTableContent(tableContent),
  373.     fTableSelection(selection),
  374.     fSavedProxy(NULL),
  375.     fSavedLinkSource(NULL),
  376.     fSavedLink(NULL)
  377. {
  378.     FW_END_CONSTRUCTOR
  379. }
  380.  
  381. //---------------------------------------------------------------------------------------
  382. // CTableEditCommand destructor
  383. //---------------------------------------------------------------------------------------
  384. CTableEditCommand::~CTableEditCommand()
  385. {
  386.     FW_START_DESTRUCTOR
  387.     
  388.     if (fSavedProxy)
  389.         fSavedProxy->Release();
  390. }
  391.  
  392. //---------------------------------------------------------------------------------------
  393. //    CTableEditCommand::UndoIt
  394. //---------------------------------------------------------------------------------------
  395. void CTableEditCommand::UndoIt(Environment* ev)
  396. {
  397.     FW_CClipboardCommand::UndoIt(ev);    // call inherited
  398.  
  399.     switch (GetCommandID(ev))
  400.     {
  401.         case kODCommandCut:
  402.         case kODCommandClear:
  403.             this->RestoreSelection(ev);
  404.             this->RestoreSavedLinks(ev);
  405.             break;
  406.  
  407.         case kODCommandPaste:
  408.             this->RemoveSelection(ev);
  409.             break;
  410.  
  411.         case kODCommandPasteAs:
  412.             this->UndoPasteAs(ev);
  413.     }    
  414. }
  415.  
  416. //---------------------------------------------------------------------------------------
  417. //    CTableEditCommand::RedoIt
  418. //---------------------------------------------------------------------------------------
  419. void CTableEditCommand::RedoIt(Environment* ev)    // Override
  420. {
  421.     FW_CClipboardCommand::RedoIt(ev);    // call inherited
  422.  
  423.     switch (GetCommandID(ev))
  424.     {
  425.         case kODCommandCut:
  426.         case kODCommandClear:
  427.             this->BreakSavedLinks(ev);    // do first, because next line causes UpdateLinkSource to be called
  428.             this->RemoveSelection(ev);
  429.             break;
  430.  
  431.         case kODCommandPaste:
  432.             this->RestoreSelection(ev);
  433.             break;
  434.  
  435.         case kODCommandPasteAs:
  436.             this->RedoPasteAs(ev);
  437.             break;    
  438.     }    
  439. }
  440.  
  441. //----------------------------------------------------------------------------------------
  442. //    CTableEditCommand::SaveUndoState
  443. //----------------------------------------------------------------------------------------
  444. void CTableEditCommand::SaveUndoState(Environment* ev)    // Override
  445. {
  446.     if (GetCommandID(ev) == kODCommandCut || GetCommandID(ev) == kODCommandClear)
  447.     {
  448.         this->SaveSelection(ev);
  449.  
  450.         // If the saved proxy is a link source or destination, save the links too
  451.         CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
  452.         CCell cell = fSavedProxy->GetCell();
  453.         fSavedLink = linkMgr->CellToLink(ev, cell);
  454.         fSavedLinkSource = linkMgr->CellToSourceLink(ev, cell);
  455.     }
  456. }
  457.  
  458. //----------------------------------------------------------------------------------------
  459. //    CTableEditCommand::FreeUndoState (called by FW_CCommand::CommitDone)
  460. //----------------------------------------------------------------------------------------
  461. void CTableEditCommand::FreeUndoState(Environment* ev)    // Override
  462. {
  463.     if (GetCommandID(ev) == kODCommandCut || GetCommandID(ev) == kODCommandClear)
  464.     {
  465.         delete fSavedLink;
  466.         delete fSavedLinkSource;
  467.     }
  468.     else if (GetCommandID(ev) == kODCommandPaste || GetCommandID(ev) == kODCommandPasteAs)
  469.     {
  470.         if (fSavedProxy)
  471.             fSavedProxy->CommitPasteDone(ev);
  472.     }
  473. }
  474.  
  475. //----------------------------------------------------------------------------------------
  476. //    CTableEditCommand::SaveRedoState
  477. //----------------------------------------------------------------------------------------
  478. void CTableEditCommand::SaveRedoState(Environment* ev)    // Override
  479. {
  480.     if (GetCommandID(ev) == kODCommandPaste)
  481.     {
  482.         this->SaveSelection(ev);
  483.     }
  484.     else if (GetCommandID(ev) == kODCommandPasteAs)
  485.     {
  486.         // If a link was created don't save the proxy;
  487.         // a new proxy is created when the link is updated
  488.         if (!WasLinkCreated(ev))
  489.             this->SaveSelection(ev);
  490.     }
  491. }
  492.  
  493. //----------------------------------------------------------------------------------------
  494. //    CTableEditCommand::PreCommand
  495. //----------------------------------------------------------------------------------------
  496. void CTableEditCommand::PreCommand(Environment* ev)
  497. {
  498.     if (GetCommandID(ev) == kODCommandCut || GetCommandID(ev) == kODCommandClear)
  499.     {
  500.         // See if there's a link spec on the clipboard for the selected item,
  501.         // and if so remove it.
  502.         FW_CLinkManager* linkMgr = fTablePart->GetLinkManager(ev);
  503.         FW_CLinkSource* linkSource = linkMgr->GetPendingClipboardLink(ev);
  504.         if (linkSource)
  505.         {    // clipboard does contain a link spec
  506.             if (linkSource->GetPendingID(ev) == fTableSelection->GetSavedLinkSpecID(ev))
  507.                 linkMgr->DeletePendingClipboardLink(ev);
  508.         }
  509.     }
  510. }
  511.  
  512. //----------------------------------------------------------------------------------------
  513. //    CTableEditCommand::CommandDone
  514. //----------------------------------------------------------------------------------------
  515. void CTableEditCommand::CommandDone(Environment* ev)
  516. {
  517.     if (GetCommandID(ev) == kODCommandPasteAs)
  518.     {
  519.         if (WasLinkCreated(ev))
  520.             fPasteAsCell = fTableSelection->GetSelectedCell();
  521.     }
  522.     else if (GetCommandID(ev) == kODCommandCopy)
  523.     {
  524.         // remember which proxy's link spec is on the clipboard
  525.         fTableSelection->SaveLinkSpecID(ev, fTablePart->GetDataInterchange(ev)->GetLastClipboardUpdateID(ev));
  526.     }
  527.     else if (GetCommandID(ev) == kODCommandCut || GetCommandID(ev) == kODCommandClear)
  528.     {
  529.         // if the proxy that was cleared was in a link source or destination, break them
  530.         this->BreakSavedLinks(ev);
  531.     }
  532. }
  533.  
  534. //----------------------------------------------------------------------------------------
  535. //    CTableEditCommand::BreakSavedLinks
  536. //----------------------------------------------------------------------------------------
  537. void CTableEditCommand::BreakSavedLinks(Environment* ev)
  538. {
  539.     // If there are saved links (from SaveUndoState), break them
  540.     if (fSavedLink)
  541.     {
  542.         fTablePart->GetLinkManager(ev)->BreakDestinationLink(ev, fSavedLink);
  543.     }
  544.     if (fSavedLinkSource)
  545.     {
  546.         fTablePart->GetLinkManager(ev)->BreakSourceLink(ev, fSavedLinkSource);
  547.     }
  548. }
  549.  
  550. //----------------------------------------------------------------------------------------
  551. //    CTableEditCommand::RestoreSavedLinks
  552. //----------------------------------------------------------------------------------------
  553. void CTableEditCommand::RestoreSavedLinks(Environment* ev)
  554. {
  555.     // If there are saved links, restore them
  556.     if (fSavedLink)
  557.     {
  558.         fTablePart->GetLinkManager(ev)->RestoreDestinationLink(ev, fSavedLink);
  559.     }
  560.     if (fSavedLinkSource)
  561.     {
  562.         fTablePart->GetLinkManager(ev)->RestoreSourceLink(ev, fSavedLinkSource);
  563.     }
  564. }
  565.  
  566. //----------------------------------------------------------------------------------------
  567. //    CTableEditCommand::WasLinkCreated
  568. //----------------------------------------------------------------------------------------
  569. FW_Boolean CTableEditCommand::WasLinkCreated(Environment* ev)
  570. {
  571.     return (GetNewLink(ev) != NULL);
  572. }
  573.  
  574. //----------------------------------------------------------------------------------------
  575. //    CTableEditCommand::FreeRedoState (called by FW_CCommand::CommitUndone)
  576. //----------------------------------------------------------------------------------------
  577.  
  578.  
  579. //---------------------------------------------------------------------------------------
  580. //    CTableEditCommand::SaveSelection
  581. //---------------------------------------------------------------------------------------
  582. void CTableEditCommand::SaveSelection(Environment* ev)
  583. {
  584. FW_UNUSED(ev);
  585.     //--- The selection is a single embedded frame ---
  586.     CCell cell = fTableSelection->GetSelectedCell();            // selected cell
  587.     
  588.     FW_ASSERT(fSavedProxy == NULL);
  589.     
  590.     fSavedProxy = fTableContent->CellToProxy(cell);
  591.     fSavedProxy->Acquire();
  592. }
  593.  
  594. //---------------------------------------------------------------------------------------
  595. //    CTableEditCommand::RestoreSelection
  596. //---------------------------------------------------------------------------------------
  597.  
  598. void CTableEditCommand::RestoreSelection(Environment* ev)
  599. {
  600.     // Re-attach the proxy's frames
  601.     fSavedProxy->AttachEmbeddedFrames(ev);
  602.  
  603.     // Add the saved proxy back into the table part
  604.     fTableContent->AddProxy(fSavedProxy);
  605.  
  606.     // Select it
  607.     fTableSelection->CloseSelection(ev);
  608.     fTableSelection->SelectProxy(ev, fSavedProxy);
  609.     fTableSelection->InvalidateSelection(ev);
  610.  
  611. }
  612.  
  613. //---------------------------------------------------------------------------------------
  614. //    CTableEditCommand::RemoveSelection
  615. //---------------------------------------------------------------------------------------
  616. void CTableEditCommand::RemoveSelection(Environment* ev)
  617. {
  618.     // Make sure the saved proxy is selected
  619.     fTableSelection->CloseSelection(ev);
  620.     fTableSelection->SelectProxy(ev, fSavedProxy);
  621.     
  622.     // Clear the selection, which includes detaching the proxy frames.
  623.     fTableSelection->ClearSelection(ev);
  624. }
  625.  
  626. //---------------------------------------------------------------------------------------
  627. //    CTableEditCommand::DeleteSavedProxy
  628. //---------------------------------------------------------------------------------------
  629.  
  630.  
  631.  
  632. //---------------------------------------------------------------------------------------
  633. // CTableEditCommand::UndoPasteAs
  634. //---------------------------------------------------------------------------------------
  635.  
  636. void CTableEditCommand::UndoPasteAs(Environment* ev)
  637. {
  638.     //--- Break the link, if there is one ---
  639.     if (WasLinkCreated(ev))
  640.     {
  641.         // with links, proxy did not exist yet when command was 'done', and may
  642.         // change between redoing and undoing get it from the cell now.
  643.         
  644.         if (fSavedProxy)
  645.             fSavedProxy->Release();
  646.             
  647.         fSavedProxy = fTableContent->CellToProxy(fPasteAsCell);
  648.         fSavedProxy->Acquire();
  649.     }
  650.     
  651.     // just like a normal Paste command
  652.     this->RemoveSelection(ev);
  653.  
  654.     //--- Force redraw ---
  655.     GetPresentation(ev)->Invalidate(ev);
  656.  
  657. }
  658.  
  659. //---------------------------------------------------------------------------------------
  660. // CTableEditCommand::RedoPasteAs
  661. //---------------------------------------------------------------------------------------
  662. void CTableEditCommand::RedoPasteAs(Environment* ev)
  663. {
  664.     this->RestoreSelection(ev);
  665. }
  666.  
  667. //========================================================================================
  668. // CTableInsertCommand class
  669. //========================================================================================
  670.  
  671. //---------------------------------------------------------------------------------------
  672. // CTableInsertCommand constructor
  673. //---------------------------------------------------------------------------------------
  674.  
  675. CTableInsertCommand::CTableInsertCommand(Environment* ev,
  676.                                          FW_CEmbeddingFrame* frame,
  677.                                          const FW_PFileSpecification& fileSpec,
  678.                                          CTablePart* itsPart,
  679.                                          const CCell& insertCell)
  680. :    FW_CInsertCommand(ev, frame, fileSpec, FW_kCanUndo),
  681.     fTablePart(itsPart),
  682.     fTableContent(NULL),
  683.     fInsertedProxy(NULL),
  684.     fInsertCell(insertCell)
  685. {
  686.     fTableContent = itsPart->GetTableContent(ev);
  687.     FW_END_CONSTRUCTOR
  688. }
  689.  
  690. //---------------------------------------------------------------------------------------
  691. // CTableInsertCommand destructor
  692. //---------------------------------------------------------------------------------------
  693.  
  694. CTableInsertCommand::~CTableInsertCommand()
  695. {
  696.     FW_START_DESTRUCTOR
  697.     
  698.     fInsertedProxy->Release();
  699. }
  700.  
  701. //---------------------------------------------------------------------------------------
  702. //    CTableInsertCommand::UndoIt
  703. //---------------------------------------------------------------------------------------
  704.  
  705. void CTableInsertCommand::UndoIt(Environment* ev)
  706. {
  707.     // activate a table frame (the inserted part may be active)
  708. //    CTableFrame* tableFrame = fTablePart->FindValidTableFrame(ev, (CTableFrame*) GetFrame(ev), (CTableFrame*) GetSourceFrame(ev));
  709. //    FW_ASSERT(tableFrame);
  710. //    tableFrame->ActivateFrame(ev, NULL);
  711.  
  712.     // remove the inserted part
  713.     CTableSelection* selection = fTablePart->GetTableSelection(ev);
  714.     selection->Select(ev, fInsertCell);
  715.     selection->ClearSelection(ev);
  716. }
  717.  
  718. //---------------------------------------------------------------------------------------
  719. //    CTableInsertCommand::RedoIt
  720. //---------------------------------------------------------------------------------------
  721.  
  722. void CTableInsertCommand::RedoIt(Environment* ev)
  723. {
  724.     // re-insert the part
  725.     fInsertedProxy->AttachEmbeddedFrames(ev);
  726.     fTableContent->AddProxy(fInsertedProxy);
  727.     CTableSelection* selection = fTablePart->GetTableSelection(ev);
  728.     selection->Select(ev, fInsertCell);
  729.     selection->InvalidateSelection(ev);
  730. }
  731.  
  732. //---------------------------------------------------------------------------------------
  733. //    CTableInsertCommand::FreeRedoState
  734. //---------------------------------------------------------------------------------------
  735.  
  736.  
  737.  
  738. //---------------------------------------------------------------------------------------
  739. //    CTableInsertCommand::SaveRedoState
  740. //---------------------------------------------------------------------------------------
  741.  
  742. void CTableInsertCommand::SaveRedoState(Environment*)
  743. {
  744.     fInsertedProxy = fTableContent->CellToProxy(fInsertCell);
  745.     fInsertedProxy->Acquire();
  746. }
  747.  
  748.  
  749.